package com.codepilot.server.controller;

import com.codepilot.server.model.vo.CommonResult;
import com.codepilot.server.model.vo.DisplayUserVO;
import com.codepilot.server.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/user")
@Api(tags = "用户信息接口")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/info")
    @ApiOperation("获取用户信息")
    public CommonResult<?> getInfo() {
        return userService.getInfo();
    }

    @PostMapping("/modify")
    @ApiOperation("更改用户信息")
    public CommonResult<?> modify(@RequestBody DisplayUserVO displayUserVO) {
        return userService.modify(displayUserVO);
    }

    @PostMapping("/avatar")
    @ApiOperation("更改/上传头像")
    public CommonResult<?> modifyAvatar(@RequestBody MultipartFile file) {
        return userService.modifyAvatar(file);
    }

    @GetMapping("/forget")
    @ApiOperation("忘记密码")
    public CommonResult<?> forget(@RequestParam("email") String email) {
        return userService.forget(email);
    }

    @GetMapping("/check-captcha")
    @ApiOperation("忘记密码时检查验证码")
    public CommonResult<?> checkCaptcha(@RequestParam("email") String email, @RequestParam("captcha") String captcha) {
        return userService.checkCaptcha(email, captcha);
    }

    @GetMapping("/passwd")
    @ApiOperation("更改密码")
    public CommonResult<?> passwd(@RequestParam("email") String email,
                                  @RequestParam("oldPassword") String oldPassword,
                                  @RequestParam("password") String password) {
        return userService.passwd(email, oldPassword, password);
    }

    @GetMapping("/logout")
    @ApiOperation("退出登录")
    public CommonResult<?> logout() {
        return userService.logout();
    }

    @GetMapping("/unregister")
    @ApiOperation("注销账户")
    public CommonResult<?> unregister() {
        return userService.unregister();
    }

}
